package com.abe.mvp.presenter;

import com.abe.mvp.contact.SocketContact;
import com.abe.mvp.model.SocketModelImp;

public class SocketPresenterImp implements SocketContact.Presenter,
		SocketContact.Model.ISocketBack {

	private SocketContact.View mView;
	private SocketContact.Model mModel;

	public SocketPresenterImp(SocketContact.View mView) {
		this.mView = mView;
		this.mModel = SocketModelImp.from(this);
	}

	@Override
	public void onResult(int code, Object data, String errorMSG) {
		switch (code) {
		case SocketModelImp.CODE_OPEN_SUCCESS:
			mView.onSocketConnectSuccess();
			break;
		case SocketModelImp.CODE_CLOSE_SUCCESS:
			mView.onSocketCloseSuccess();
			break;
		case SocketModelImp.CODE_SEND_DATA_SUCCESS:
			mView.onSocketSendDataSuccess();
			break;
		case SocketModelImp.CODE_RECEIVE_DATA_SUCCESS:
			mView.onSocketReceiveDataSuccess(data.toString());
			break;
		case SocketModelImp.CODE_ERROR:
			mView.onSocketError(errorMSG);
			break;
		default:
			break;
		}
	}

	@Override
	public void openSocket(String IP, int Port) {
		mModel.openSocket(IP, Port);
	}

	@Override
	public void sendSocketCommand(String msg) {
		mModel.sendSocketCommand(msg);
	}

	@Override
	public void closeSocket() {
		mModel.closeSocket();
	}

	@Override
	public void checkScoket() {
		mModel.checkScoket();
	}

}
